/*
 * Copyright (c) 2003, 2004 Ulrich Hilger, http://dev.uhilger.de, all rights reserved.
 *
 * Published under the terms and conditions of the Apache License 2.0,
 * see http://www.apache.org/licenses/LICENSE-2.0
 */

package de.uhilger.app.ui;

import java.awt.Container;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JComponent;
import java.awt.Insets;

/**
 * GridBagHelper provides some helper methods to work with
 * GridBagLayouts.
 *
 * <p>The class typically is instanciated locally and temporary inside a method that builds a gui. 
 * Once all gui elements are layed out, this class can be freed again.</p>
 *
 * @author Ulrich Hilger, <a href="http://dev.uhilger.de" target="_blank">http://dev.uhilger.de</a>
 * @author Published under the terms and conditions of
 * the <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License 2.0</a>
 *
 * @version Version 2, June 14, 2004
 */

public class GridBagHelper {

  /**
   * constructor
   */
  public GridBagHelper() {
  }

  /**
   * convenience method for adding a component to a container
   * layed out by a GridBagLayout
   *
   * @param container  the container to add a component to
   * @param comp  the component to add to container
   * @param g  the GridBagLayout associated with container
   * @param c  the GridBagConstraints to use
   * @param gx  the value to use for GridBagConstraints.gridx
   * @param gy  the value to use for GridBagConstraints.gridy
   * @param a  the value to use for GridBagConstraints.anchor
   */
  public void addGridBagComponent(Container container, JComponent comp,
        GridBagLayout g, GridBagConstraints c, int gx, int gy, int a)
  {
    addGridBagComponent(container, comp, g, c, gx, gy, a, 1, 1, GridBagConstraints.NONE, 0, 0);
  }

  /**
   * convenience method for adding a component to a container
   * layed out by a GridBagLayout
   *
   * @param container  the container to add a component to
   * @param comp  the component to add to container
   * @param g  the GridBagLayout associated with container
   * @param c  the GridBagConstraints to use
   * @param gx  the value to use for GridBagConstraints.gridx
   * @param gy  the value to use for GridBagConstraints.gridy
   * @param a  the value to use for GridBagConstraints.anchor
   * @param gw  the value to use for GridBagConstraints.gridwidth
   * @param gh  the value to use for GridBagConstraints.gridheight
   * @param f  the value to use for GridBagConstraints.fill
   * @param wx  the value to use for GridBagConstraints.weightx
   * @param wy  the value to use for GridBagConstraints.weighty
   */
  public void addGridBagComponent(Container container, JComponent comp, GridBagLayout g, GridBagConstraints c,
                                   int gx, int gy, int a, int gw, int gh, int f, double wx, double wy)
  {
    c.gridx = gx;
    c.gridy = gy;
    c.anchor = a;
    c.insets = new Insets(2, 2, 2, 2);
    c.ipadx = 2;
    c.ipady = 2;
    c.gridwidth = gw;
    c.gridheight = gh;
    c.fill = f;
    c.weightx = wx;
    c.weighty = wy;
    g.setConstraints(comp, c);
    container.add(comp);
  }

}
